package com.cennavi.buss.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cennavi.buss.service.imp.ILayerService;
import com.cennavi.minemap.bean.MessageBean;

@RestController
@RequestMapping("/service/layer")
public class LayerController {
    @Autowired
    private ILayerService iLayerService;

    @RequestMapping(method = RequestMethod.POST, value = "/add", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean insert(@RequestBody String json) {
        return iLayerService.insert(json);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/update", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean update(@RequestBody String json) {
        return iLayerService.update(json);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/update/{field}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean updateStyle(@PathVariable String field, @RequestBody String json) {
        return iLayerService.updateStyle(field, json);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/delete/{id}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean delete(@PathVariable String id) {
        return iLayerService.delete(id);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean queryById(@PathVariable String id) {
        return iLayerService.queryById(id);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/list/{soluId}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean queryBySoluId(@PathVariable int soluId) {
        return iLayerService.queryBySoluId(soluId);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/sort/{soluId}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean sort(@RequestBody String json, @PathVariable int soluId) {
        return iLayerService.sort(json, soluId);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/group/update", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean updateGroup(@RequestBody String json) {
        return iLayerService.updateGroup(json);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/visibility", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean updateVisibility(@RequestBody String json) {
        return iLayerService.updateVisibility(json);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/prefix/byCode/{code}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean queryLayerPerfixTreeByCode(@PathVariable String code) {
        return iLayerService.queryLayerPerfixTreeByCode(code);
    }

    @RequestMapping(method = RequestMethod.GET, value = "/prefix/getTree/{father}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean queryLayerPerfixTreeByFather(@PathVariable String father) {
        return iLayerService.queryLayerPerfixTreeByFather(father);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/batch/update/{field}", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean updateLayersStyle(@PathVariable String field, @RequestBody String json) {
        return iLayerService.updateLayersStyle(field, json);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/prefix/update", produces = "application/json;charset=UTF-8")
    public @ResponseBody MessageBean updateLayersPrefix(@RequestBody String json) {
        return iLayerService.updateLayersPrefix(json);
    }
}
